<template>
    <div>
        <Modal v-model="showModal" width="600" @on-cancel="rightClose" draggable>
            <p slot="header" style="color:#f60;text-align:center;">
                {{ deploy_name }}<span>删除容忍</span>
            </p>
            <div style="">
                <Form>
                    <Form-Item >
                        <Radio-Group v-model="toleration_del_index" vertical>
                            <Radio v-for="(toleration,index) in tolerations" :label="index" :key="index">{{ toleration }}</Radio>
                        </Radio-Group>
                    </Form-Item> 
                </Form> 
            </div>
            <div slot="footer">
                <Button  size="default"  type="primary"   @click="submit_del_toleration">提交</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import {k8s_namespace_post} from '@/api/http'
import {  delete_toleration } from  '@/api'
export default ({
    name: 'deleteTolerationModal',
    props: {
        isShow: {
            type: Boolean
        }, 
        deploy_name: {
            type: String
        },
        tolerations:{
            type: Array,
        },
    },
    data() {
        return {
            showModal: false,
            toleration_del_index: null,
        }
    },
    methods: {
        rightClose() {
            this.$emit('closeModal')
        },
        // 提交删除容忍事件
        submit_del_toleration(){
            let  toleration= this.tolerations[this.toleration_del_index]
            if (toleration.tolerationSeconds != null) {
                toleration.tolerationSeconds = parseInt( toleration.tolerationSeconds)
            }
            let data={
                "name":this.deploy_name,
                "toleration":toleration
            }
            k8s_namespace_post(delete_toleration,data).then( (response) => {
                let info = JSON.stringify(response.data)
                if(info.indexOf('ok') != -1) {
                     this.$Message.success('删除容忍成功')
                    this.$emit('deleteSuccess')
                    this.$emit('closeModal')
                }else {
                    alert(info)
                }
            })
        },
    },
    watch: {
        isShow(newVal,oldVal) {
            console.log("监听到isShow变化"+newVal,oldVal)
            this.showModal = newVal
        }
    }
})


</script>
